package com.hjm.admin.moule.db.helpter;

import com.hjm.admin.moule.db.entity.UserBean;
import com.hjm.admin.moule.db.gen.DaoSession;
import com.hjm.admin.moule.db.gen.UserBeanDao;

public class UserHelper {
    private static volatile UserHelper sInstance;
    private static DaoSession daoSession;
    private static UserBeanDao userBeanDao;

    public static UserHelper getsInstance() {
        if (sInstance == null) {
            synchronized (UserHelper.class) {
                if (sInstance == null) {
                    sInstance = new UserHelper();
                    daoSession = DaoDbHelper.getInstance().getSession();
                    userBeanDao = daoSession.getUserBeanDao();
                }
            }
        }
        return sInstance;
    }

    public void saveUser(UserBean userBean) {
        userBeanDao.insertOrReplace(userBean);
    }

    public void updateUser(UserBean userBean) {
        userBeanDao.update(userBean);
    }

    public void removeUser() {
        userBeanDao.deleteAll();
    }

    public UserBean findUserByName(String name) {
        return userBeanDao.queryBuilder().where(UserBeanDao.Properties.Name.eq(name)).unique();
    }
}
